﻿package com.dd.action;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;

import com.dd.action.form.MainForm;
import com.dd.dao.DdShopDAO;
import com.dd.dao.DdShopgoodsDAO;
import com.dd.entity.DdShop;
import com.dd.entity.DdShopgoods;
import com.dd.entity.DdSystemuser;
import com.dd.entity.Dict;
import com.dd.service.ShopService;
import com.dd.util.DateStrFormat;
import com.dd.util.PageList;
import com.dd.util.UpFile;

public class ShopSupportAction extends BaseAction {

	public ActionForward showNewShop(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		try {
			StringBuffer sbf = new StringBuffer("");
			Integer logid = (Integer) request.getSession().getAttribute(
					"systemlogid");// 系统用户是否已经登录
			if (logid == null) {// 商家用户尚未登录
				// 返回-1
				// out.print("{\"result\":\"-1\"}");
				// return null;
			}
			String id = request.getParameter("id");
			DdShop ds = this.getShopService().getDdShopDAO().findById(
					Integer.parseInt(id));
			if (ds == null) {// 对象不存在
				out.print("{\"result\":\"-2\"}");
				return null;
			}

			DdSystemuser dsu = this.getDdSystemuserDAO().findByShopid(
					ds.getId());
			String shopLoginid = "";
			String shopLoginPass = "";
			if (dsu != null) {
				shopLoginid = dsu.getLogid();
				shopLoginPass = dsu.getPassword();
			}
			sbf.append("{");
			sbf.append("\"name\":\"" + clearStr(ds.getName()) + "\"");
			sbf.append(",\"ywy\":\"" + ds.getBelong() + "\"");
			sbf.append(",\"enddate\":\"" + getDateStr(ds.getEnddate()) + "\"");
			sbf.append(",\"syslogid\":\"" + shopLoginid + "\"");
			sbf.append(",\"syslogpas\":\"" + shopLoginPass + "\"");
			sbf.append(",\"bankacc\":\"" + ds.getBankacc() + "\"");
			sbf.append(",\"bankaccname\":\"" + ds.getBankaccname() + "\"");
			sbf.append(",\"address\":\"" + clearStr(ds.getAddress()) + "\"");
			sbf.append(",\"posx\":\"" + clearStr(ds.getPosx()) + "\"");
			sbf.append(",\"posy\":\"" + clearStr(ds.getPosy()) + "\"");
			sbf.append(",\"phone\":\"" + clearStr(ds.getPhone()) + "\"");
			sbf.append(",\"mobile\":\"" + clearStr(ds.getMobile()) + "\"");
			sbf
					.append(",\"bossphone\":\"" + clearStr(ds.getBossphone())
							+ "\"");
			sbf.append(",\"landmark\":\"" + clearStr(ds.getLandmark()) + "\"");
			sbf
					.append(",\"shophours\":\"" + clearStr(ds.getShophours())
							+ "\"");
			String cost = "0-50";
			if (ds.getCost() != null && ds.getCost().intValue() == 2) {
				cost = "50-100";
			} else if (ds.getCost() != null && ds.getCost().intValue() == 3) {
				cost = "100-200";
			} else if (ds.getCost() != null && ds.getCost().intValue() == 4) {
				cost = "200以上";
			}
			String shopstyle = "其他";
			// "请直接填入:1,2,3,4 ……
			// 1.私房菜 2.自助餐 3.川湘菜 4.粤菜 5.闽菜 6.西餐7.日本料理 8.泰国菜 9.韩国料理 10.越南菜 11.快餐
			// "
			if (ds.getShopstyle() != null && ds.getShopstyle().intValue() == 1) {
				shopstyle = "私房菜";
			} else if (ds.getShopstyle() != null
					&& ds.getShopstyle().intValue() == 2) {
				shopstyle = "自助餐";
			} else if (ds.getShopstyle() != null
					&& ds.getShopstyle().intValue() == 3) {
				shopstyle = "川湘菜";
			} else if (ds.getShopstyle() != null
					&& ds.getShopstyle().intValue() == 4) {
				shopstyle = "粤菜";
			} else if (ds.getShopstyle() != null
					&& ds.getShopstyle().intValue() == 5) {
				shopstyle = "闽菜";
			} else if (ds.getShopstyle() != null
					&& ds.getShopstyle().intValue() == 6) {
				shopstyle = "西餐";
			} else if (ds.getShopstyle() != null
					&& ds.getShopstyle().intValue() == 7) {
				shopstyle = "日本料理";
			} else if (ds.getShopstyle() != null
					&& ds.getShopstyle().intValue() == 8) {
				shopstyle = "泰国菜";
			} else if (ds.getShopstyle() != null
					&& ds.getShopstyle().intValue() == 9) {
				shopstyle = "韩国料理";
			} else if (ds.getShopstyle() != null
					&& ds.getShopstyle().intValue() == 10) {
				shopstyle = "越南菜";
			} else if (ds.getShopstyle() != null
					&& ds.getShopstyle().intValue() == 11) {
				shopstyle = "外卖";
			}
			sbf.append(",\"cost\":\"" + cost + "\"");
			sbf.append(",\"shopstyle\":\"" + shopstyle + "\"");
			sbf.append(",\"wifi\":\"" + (ds.getWifi() == 0 ? "无" : "有") + "\"");
			sbf.append(",\"visa\":\"" + (ds.getVisa() == 0 ? "无" : "有") + "\"");
			String park = "无";
			if (ds.getPark().intValue() == 0) {
				park = "免费车位";
			} else if (ds.getPark().intValue() > 0) {
				park = "收费车位:" + ds.getPark() + "元";
			}
			sbf.append(",\"park\":\"" + park + "\"");
			sbf.append(",\"shoptype\":\""
					+ (ds.getShoptype() == 1 ? "独家" : "连锁") + "\"");
			sbf.append(",\"bus\":\"" + clearStr(ds.getBus()) + "\"");
			sbf.append(",\"sendtype\":\""
					+ (ds.getSendtype() == 1 ? "外送" : "自取") + "\"");
			sbf.append(",\"sendtime\":\"" + clearStr(ds.getSendtime()) + "\"");
			sbf
					.append(",\"sendrange\":\"" + clearStr(ds.getSendrange())
							+ "\"");
			sbf.append(",\"sendreq\":\"" + clearStr(ds.getSendreq()) + "\"");
			sbf.append(",\"sendfee\":\"" + clearStr(ds.getSendfee()) + "\"");
			sbf.append(",\"sendpaymethod\":\""
					+ (ds.getSendpaymethod() == 1 ? "到付" : "在线付款") + "\"");
			sbf.append(",\"senddiscount\":\"" + clearStr(ds.getSenddiscount())
					+ "\"");
			sbf.append(",\"loge0\":\""+(ds.getLoge0()==0?"无":"有")+"\"");
			sbf.append(",\"loge1\":\""+(ds.getLoge1()==0?"无":"有")+"\"");
			sbf.append(",\"bookprice\":\"" + ds.getBookprice() + "\"");
			sbf.append(",\"bookpriceuse\":\"" + clearStr(ds.getBookpriceuse())
					+ "\"");
			sbf.append(",\"pricedivide\":\"" + clearStr(ds.getPricedivide())
					+ "\"");
			sbf.append(",\"bookreq\":\"" + clearStr(ds.getBookreq()) + "\"");
			String discount = "";
			if (ds.getDiscount() > 0F && ds.getDiscount() < 10F) {
				discount = ds.getDiscount() + "折";
			}
			sbf.append(",\"discount\":\"" + discount + "\"");
			sbf.append(",\"coupon3\":\"" + clearStr(ds.getCoupon3()) + "\"");
			sbf.append("}");
			// System.out.println(sbf.toString());
			out.print(sbf.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public ActionForward editShop(ActionMapping mapping, ActionForm pcUserForm,
			HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		Integer logid = (Integer) request.getSession().getAttribute(
				"systemlogid");// 系统用户是否已经登录
		if (logid == null) {// 商家用户尚未登录
			// 返回-1
			// out.print("{\"result\":\"-1\"}");
			// return null;
		}
		String id = request.getParameter("id");
		DdShop ds = this.getShopService().getDdShopDAO().findById(
				Integer.parseInt(id));
		if (ds == null) {// 对象不存在
			out.print("{\"result\":\"-2\"}");
			return null;
		}
		String syslogid = request.getParameter("syslogid");
		String syslogpas = request.getParameter("syslogpas");
		String bankacc = request.getParameter("bankacc");
		String bankaccname = request.getParameter("bankaccname");
		String posx = request.getParameter("posx");
		String posy = request.getParameter("posy");
		String coupon3 = request.getParameter("coupon3");
		try {
			Float.parseFloat(posx);
			Float.parseFloat(posy);
			ds.setPosx(posx);
			ds.setPosy(posy);
			ds.setCoupon3(coupon3);
			ds.setBankacc(bankacc);
			ds.setBankaccname(bankaccname);
			if (syslogid != null && syslogid.trim().length() > 1) {
				DdSystemuser dsu = this.getDdSystemuserDAO().findByShopid(
						ds.getId());
				if (dsu != null) {
					dsu.setLogid(syslogid);
					dsu.setPassword(syslogpas);
				} else {
					dsu = new DdSystemuser();
					dsu.setName(ds.getName());
					dsu.setLogid(syslogid);
					dsu.setPassword(syslogpas);
					dsu.setShopid(ds.getId());
					dsu.setType(6);

				}
				this.getDdSystemuserDAO().save(dsu);
			}
			this.getDdShopDAO().saveOrUpdate(ds);
			out.print("{\"result\":\"1\"}");
		} catch (Exception e) {
			e.printStackTrace();
			out.print("{\"result\":\"0\"}");
		}

		return null;
	}

	public ActionForward newshop(ActionMapping mapping, ActionForm pcUserForm,
			HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");

		PrintWriter out = response.getWriter();
		Integer logid = (Integer) request.getSession().getAttribute(
				"systemlogid");// 系统用户是否已经登录

		if (logid == null) {// 商家用户尚未登录
			// 返回-1
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><result>-1</result></root>");
			return null;
		}
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		try {
			DdShop ds = new DdShop();
			List list = this.getDdShopDAO().findByName(
					request.getParameter("name"),1);
			String id = request.getParameter("id");
			if (id != null & id.trim().length() > 0) {
				ds = this.getDdShopDAO().findById(Integer.parseInt(id));
				if (ds == null) {
					sbf.append("<result>0</result></root>");
					out.print(sbf.toString());
					return null;
				}
				this.getShopService().editShop(request, ds, sbf);
				out.print(sbf.toString());
			} else {
				if (list.size() != 0) {
					sbf.append("<result>2</result></root>");
					out.print(sbf.toString());
					return null;
				} else {
					ds.setIsnew(1);
					this.getShopService().newShop(request, ds, sbf);
					// out.print(sbf.toString());

					out.print(sbf.toString());
					// System.out.println(sbf.toString());
				}
			}
			return null;
		} catch (Exception e) {
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><result>0</result></root>");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	public ActionForward updateAlive(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		Integer logid = (Integer) request.getSession().getAttribute(
				"systemlogid");// 系统用户是否已经登录

		if (logid == null) {// 用户尚未登录
			// 返回-1
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><result>-1</result></root>");
			return null;
		}
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		String id = request.getParameter("id");
		String type = request.getParameter("type");
		String alive = request.getParameter("alive");
		int i_alive = 0;
		if (alive != null && alive.trim().equals("0")) {
			i_alive = 1;
		} else {
			i_alive = 0;
		}
		try {
			if (type.equals("1")) {
				ShopService ss = this.getShopService();// 获取商家Servcie
				DdShop ds = ss.getDdShopDAO().findById(Integer.parseInt(id));
				ds.setAlive(i_alive);
				if (i_alive == 1) {// 生效
					if (ds.getAlivedate() == null) {
						ds.setAlivedate(new Date());
					}
				}
				ss.getDdShopDAO().saveOrUpdate(ds);
			} else {
				DdShopgoodsDAO dsdd = this.getDdGoodDAO();
				DdShopgoods ds = dsdd.findById(Integer.parseInt(id));
				ds.setAlive(i_alive);
				dsdd.saveOrUpdate(ds);
			}
			sbf.append("<result>1</result></root>");
		} catch (Exception e) {
			sbf.append("<result>0</result></root>");
		}
		out.print(sbf.toString());
		return null;
	}

	// 根据生效期查询商家
	public ActionForward queryShop1(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();

		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		Integer logid = (Integer) request.getSession().getAttribute(
				"systemlogid");// 系统用户是否已经登录

		if (logid == null) {// 商家用户尚未登录
			// 返回-1
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><result>-1</result></root>");
			return null;
		}
		String pageNo = request.getParameter("pageno");// 第几页
		String pageSize = request.getParameter("pagesize");// 每页记录数
		String name = request.getParameter("name");// 商家名称
		String alive = request.getParameter("alive");// 是否发布
		String shoptype = request.getParameter("shoptype");// 商家类型 
		String book = request.getParameter("book");// 商家类型 
		String send = request.getParameter("send");// 商家类型 
		String coupon = request.getParameter("coupon");// 商家类型 
		String onwer = request.getParameter("onwer");// 是否发布
		String sdate = request.getParameter("sdate");// 是否发布
		String edate = request.getParameter("edate");// 是否发布
		int i_pageNo = 1;
		if (pageNo != null && pageNo.trim().length() > 0) {
			i_pageNo = Integer.parseInt(pageNo);
		} else {
			i_pageNo = 1;
		}
		int i_pageSize = 10;
		if (pageSize != null && pageSize.trim().length() > 0) {
			i_pageSize = Integer.parseInt(pageSize);
		} else {
			i_pageSize = 10;
		}
		String sqlwhere = "";
		if (name != null && name.trim().length() > 0) {
			sqlwhere += " and name like '%" + name + "%'";
		}
		if (onwer != null && onwer.trim().length() > 0 && !onwer.equals("-1")) {
			sqlwhere += " and belong= " + onwer;
		}
		if (sdate != null && sdate.trim().length() > 0) {
			sqlwhere += (" and alivedate>='" + sdate + "'");
		}
		if (edate != null && edate.trim().length() > 0) {
			sqlwhere += (" and alivedate<='" + edate + "'");
		}
		if (shoptype != null && shoptype.trim().length() > 0) {
			if (shoptype.equals("-1")) {
				
			} else {
				sqlwhere += " and isnew =" + shoptype;
			}

		}
		//0代表不送
		if (book != null && book.trim().length() > 0) {
			if (book.equals("0")) {
				
			} else {
				sqlwhere += " and isbooking =" + book;
			}

		}
		if (send != null && send.trim().length() > 0) {
			if (send.equals("0")) {
				
			} else {
				sqlwhere += " and issend =" + send;
			}

		}
		if (coupon != null && coupon.trim().length() > 0) {
			if (coupon.equals("0")) {
				
			} else {
				sqlwhere += " and iscoupon =" + coupon;
			}

		}
		if (alive != null && alive.trim().length() > 0) {
			if (alive.equals("-1")) {
				sqlwhere += " and alive in (0,1)";
			} else {
				sqlwhere += " and alive =" + alive;
			}

		}
		try {
			PageList list = this.getDdShopDAO().findAll(sqlwhere, i_pageNo,
					i_pageSize);
			sbf.append("<shops total=\"" + list.getTotalCount() + "\">");
			for (int i = 0; i < list.size(); i++) {

				DdShop ddShop = (DdShop) list.get(i);
				String str = ddShop.getAlive() == 1 ? "是" : "否";
				sbf.append("<shop name=\"" + ddShop.getName() + "\" types=\""
						+ ddShop.getType() + "\" id=\"" + ddShop.getId()
						+ "\" address=\"" + ddShop.getAddress() + "\" phone=\""
						+ ddShop.getPhone() + "\"  alive_str=\"" + str
						+ "\" alive=\"" + ddShop.getAlive() + "\" />");
			}
			sbf.append("</shops></root>");
			// System.out.println(sbf.toString());
			out.print(sbf.toString());
			return null;
		} catch (Exception e) {
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>0</error></root>");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	public ActionForward queryShop(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();

		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		Integer logid = (Integer) request.getSession().getAttribute(
				"systemlogid");// 系统用户是否已经登录

		if (logid == null) {// 商家用户尚未登录
			// 返回-1
			out.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><result>-1</result></root>");
			return null;
		}
		String pageNo = request.getParameter("pageno");// 第几页
		String pageSize = request.getParameter("pagesize");// 每页记录数
		String name = request.getParameter("name");// 商家名称
		String alive = request.getParameter("alive");// 是否发布
		String shoptype = request.getParameter("shoptype");// 商家类型 
		String book = request.getParameter("book");// 商家类型 
		String send = request.getParameter("send");// 商家类型 
		String coupon = request.getParameter("coupon");// 商家类型 
		String onwer = request.getParameter("onwer");// 是否发布
		String sdate = request.getParameter("sdate");// 是否发布
		String edate = request.getParameter("edate");// 是否发布
		int i_pageNo = 1;
		if (pageNo != null && pageNo.trim().length() > 0) {
			i_pageNo = Integer.parseInt(pageNo);
		} else {
			i_pageNo = 1;
		}
		int i_pageSize = 10;
		if (pageSize != null && pageSize.trim().length() > 0) {
			i_pageSize = Integer.parseInt(pageSize);
		} else {
			i_pageSize = 10;
		}
		String sqlwhere = "";
		if (name != null && name.trim().length() > 0) {
			sqlwhere += " and name like '%" + name + "%'";
		}
		if (onwer != null && onwer.trim().length() > 0 && !onwer.equals("-1")) {
			sqlwhere += " and belong= " + onwer;
		}
		if (sdate != null && sdate.trim().length() > 0) {
			sqlwhere += (" and createdate>='" + sdate + "'");
		}
		if (edate != null && edate.trim().length() > 0) {
			sqlwhere += (" and createdate<='" + edate + "'");
		}
		if (shoptype != null && shoptype.trim().length() > 0) {
			if (shoptype.equals("-1")) {
				
			} else {
				sqlwhere += " and isnew =" + shoptype;
			}

		}
		//0代表不送
		if (book != null && book.trim().length() > 0) {
			if (book.equals("0")) {
				
			} else {
				sqlwhere += " and isbooking =" + book;
			}

		}
		if (send != null && send.trim().length() > 0) {
			if (send.equals("0")) {
				
			} else {
				sqlwhere += " and issend =" + send;
			}

		}
		if (coupon != null && coupon.trim().length() > 0) {
			if (coupon.equals("0")) {
				
			} else {
				sqlwhere += " and iscoupon =" + coupon;
			}

		}
		if (alive != null && alive.trim().length() > 0) {
			if (alive.equals("-1")) {
				sqlwhere += " and alive in (0,1)";
			} else {
				sqlwhere += " and alive =" + alive;
			}

		}
		try {
			PageList list = this.getDdShopDAO().findAll(sqlwhere, i_pageNo,
					i_pageSize);
			sbf.append("<shops total=\"" + list.getTotalCount() + "\">");
			for (int i = 0; i < list.size(); i++) {

				DdShop ddShop = (DdShop) list.get(i);
				String str = ddShop.getAlive() == 1 ? "是" : "否";
				sbf.append("<shop name=\"" + ddShop.getName() + "\" types=\""
						+ ddShop.getType() + "\" id=\"" + ddShop.getId()
						+ "\" address=\"" + ddShop.getAddress() + "\" phone=\""
						+ ddShop.getPhone() + "\"  alive_str=\"" + str
						+ "\" alive=\"" + ddShop.getAlive() + "\" />");
			}
			sbf.append("</shops></root>");
			// System.out.println(sbf.toString());
			out.print(sbf.toString());
			return null;
		} catch (Exception e) {
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>0</error></root>");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	public ActionForward showArea(ActionMapping mapping, ActionForm pcUserForm,
			HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();

		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		Integer logid = (Integer) request.getSession().getAttribute(
				"systemlogid");// 系统用户是否已经登录

		if (logid == null) {// 商家用户尚未登录
			// 返回-1
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><result>-1</result></root>");
			return null;
		}
		List list = this.getShopService().getArea();
		for (int i = 0; i < list.size(); i++) {
			Dict d = (Dict) list.get(i);
			sbf.append("<dict code=\"" + d.getNodeCode() + "\"  value=\""
					+ d.getNodeValue() + "\" />");
		}
		sbf.append("</root>");
		// System.out.println(sbf.toString());
		out.print(sbf.toString());
		return null;
	}

	public ActionForward showOnwer(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");

		List list = this.getDdSystemuserDAO().findByType(4);
		for (int i = 0; i < list.size(); i++) {
			DdSystemuser d = (DdSystemuser) list.get(i);
			if (d.getPassword().indexOf("del") != -1) {
				continue;
			}
			sbf.append("<dict code=\"" + d.getId() + "\"  value=\""
					+ d.getName() + "\" />");
		}
		list = this.getDdSystemuserDAO().findByType(3);
		for (int i = 0; i < list.size(); i++) {
			DdSystemuser d = (DdSystemuser) list.get(i);
			sbf.append("<dict code=\"" + d.getId() + "\"  value=\""
					+ d.getName() + "\" />");
		}
		sbf.append("</root>");
		// System.out.println(sbf.toString());
		out.print(sbf.toString());
		return null;
	}

	public ActionForward getOnwer(ActionMapping mapping, ActionForm pcUserForm,
			HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		Integer logid = (Integer) request.getSession().getAttribute(
				"systemlogid");// 系统用户是否已经登录

		if (logid == null) {// 商家用户尚未登录
			// 返回-1
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><result>-1</result></root>");
			return null;
		}
		List list = this.getShopService().getCTCost();
		for (int i = 0; i < list.size(); i++) {
			Dict d = (Dict) list.get(i);
			sbf.append("<dict code=\"" + d.getNodeCode() + "\"  value=\""
					+ d.getNodeValue() + "\" />");
		}
		sbf.append("</root>");
		// System.out.println(sbf.toString());
		out.print(sbf.toString());
		return null;
	}

	public ActionForward getCTCost(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		Integer logid = (Integer) request.getSession().getAttribute(
				"systemlogid");// 系统用户是否已经登录

		if (logid == null) {// 商家用户尚未登录
			// 返回-1
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><result>-1</result></root>");
			return null;
		}
		List list = this.getShopService().getCTCost();
		for (int i = 0; i < list.size(); i++) {
			Dict d = (Dict) list.get(i);
			sbf.append("<dict code=\"" + d.getNodeCode() + "\"  value=\""
					+ d.getNodeValue() + "\" />");
		}
		sbf.append("</root>");
		// System.out.println(sbf.toString());
		out.print(sbf.toString());
		return null;
	}

	public ActionForward getScCost(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		Integer logid = (Integer) request.getSession().getAttribute(
				"systemlogid");// 系统用户是否已经登录

		if (logid == null) {// 商家用户尚未登录
			// 返回-1
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><result>-1</result></root>");
			return null;
		}
		List list = this.getShopService().getScCost();
		for (int i = 0; i < list.size(); i++) {
			Dict d = (Dict) list.get(i);
			sbf.append("<dict code=\"" + d.getNodeCode() + "\"  value=\""
					+ d.getNodeValue() + "\" />");
		}
		sbf.append("</root>");
		// System.out.println(sbf.toString());
		out.print(sbf.toString());
		return null;
	}

	public ActionForward getYlCost(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		Integer logid = (Integer) request.getSession().getAttribute(
				"systemlogid");// 系统用户是否已经登录

		if (logid == null) {// 商家用户尚未登录
			// 返回-1
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><result>-1</result></root>");
			return null;
		}
		List list = this.getShopService().getYlCost();
		for (int i = 0; i < list.size(); i++) {
			Dict d = (Dict) list.get(i);
			sbf.append("<dict code=\"" + d.getNodeCode() + "\"  value=\""
					+ d.getNodeValue() + "\" />");
		}
		sbf.append("</root>");
		// System.out.println(sbf.toString());
		out.print(sbf.toString());
		return null;
	}

	public ActionForward getYdCost(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		Integer logid = (Integer) request.getSession().getAttribute(
				"systemlogid");// 系统用户是否已经登录

		if (logid == null) {// 商家用户尚未登录
			// 返回-1
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><result>-1</result></root>");
			return null;
		}
		List list = this.getShopService().getYdCost();
		for (int i = 0; i < list.size(); i++) {
			Dict d = (Dict) list.get(i);
			sbf.append("<dict code=\"" + d.getNodeCode() + "\"  value=\""
					+ d.getNodeValue() + "\" />");
		}
		sbf.append("</root>");
		// System.out.println(sbf.toString());
		out.print(sbf.toString());
		return null;
	}

	public ActionForward getScSendto(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		Integer logid = (Integer) request.getSession().getAttribute(
				"systemlogid");// 系统用户是否已经登录

		if (logid == null) {// 商家用户尚未登录
			// 返回-1
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><result>-1</result></root>");
			return null;
		}
		String sendto = "," + request.getParameter("sendto") + ",";
		List list = this.getShopService().getScSendto();
		for (int i = 0; i < list.size(); i++) {
			Dict d = (Dict) list.get(i);
			if (sendto.indexOf("," + d.getNodeCode() + ",") > -1) {
				sbf.append("<dict code=\"" + d.getNodeCode() + "\"  value=\""
						+ d.getNodeValue() + "\" checked=\"1\" />");
			} else {
				sbf.append("<dict code=\"" + d.getNodeCode() + "\"  value=\""
						+ d.getNodeValue() + "\" checked=\"0\"/>");
			}
		}
		sbf.append("</root>");
		// System.out.println(sbf.toString());
		out.print(sbf.toString());
		return null;
	}

	public ActionForward showCTStyletype(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		Integer logid = (Integer) request.getSession().getAttribute(
				"systemlogid");// 系统用户是否已经登录

		if (logid == null) {// 商家用户尚未登录
			// 返回-1
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><result>-1</result></root>");
			return null;
		}
		List list = this.getShopService().getCTStyletype();
		for (int i = 0; i < list.size(); i++) {
			Dict d = (Dict) list.get(i);
			sbf.append("<dict code=\"" + d.getNodeCode() + "\"  value=\""
					+ d.getNodeValue() + "\" />");
		}
		sbf.append("</root>");
		// System.out.println(sbf.toString());
		out.print(sbf.toString());
		return null;
	}

	public ActionForward showScStyletype(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		Integer logid = (Integer) request.getSession().getAttribute(
				"systemlogid");// 系统用户是否已经登录

		if (logid == null) {// 商家用户尚未登录
			// 返回-1
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><result>-1</result></root>");
			return null;
		}
		List list = this.getShopService().getScStyletype();
		for (int i = 0; i < list.size(); i++) {
			Dict d = (Dict) list.get(i);
			sbf.append("<dict code=\"" + d.getNodeCode() + "\"  value=\""
					+ d.getNodeValue() + "\" />");
		}
		sbf.append("</root>");
		// System.out.println(sbf.toString());
		out.print(sbf.toString());
		return null;
	}

	public ActionForward showCTStyle(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		Integer logid = (Integer) request.getSession().getAttribute(
				"systemlogid");// 系统用户是否已经登录

		if (logid == null) {// 商家用户尚未登录
			// 返回-1
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><result>-1</result></root>");
			return null;
		}
		String styletype = request.getParameter("styletype");
		String style = "," + request.getParameter("style") + ",";
		List list = this.getShopService().getCTStyle(
				Integer.parseInt(styletype));
		for (int i = 0; i < list.size(); i++) {
			Dict d = (Dict) list.get(i);
			if (style.indexOf("," + d.getNodeCode() + ",") > -1) {
				sbf.append("<dict code=\"" + d.getNodeCode() + "\"  value=\""
						+ d.getNodeValue() + "\" checked=\"1\"/>");
			} else {
				sbf.append("<dict code=\"" + d.getNodeCode() + "\"  value=\""
						+ d.getNodeValue() + "\"  checked=\"0\" />");
			}
		}
		sbf.append("</root>");
		// System.out.println(sbf.toString());
		out.print(sbf.toString());
		return null;
	}

	public ActionForward showScStyle(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		Integer logid = (Integer) request.getSession().getAttribute(
				"systemlogid");// 系统用户是否已经登录

		if (logid == null) {// 商家用户尚未登录
			// 返回-1
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><result>-1</result></root>");
			return null;
		}
		String styletype = request.getParameter("styletype");
		String style = "," + request.getParameter("style") + ",";
		List list = this.getShopService().getScStyle(
				Integer.parseInt(styletype));
		for (int i = 0; i < list.size(); i++) {
			Dict d = (Dict) list.get(i);
			if (style.indexOf("," + d.getNodeCode() + ",") > -1) {
				sbf.append("<dict code=\"" + d.getNodeCode() + "\"  value=\""
						+ d.getNodeValue() + "\" checked=\"1\"/>");
			} else {
				sbf.append("<dict code=\"" + d.getNodeCode() + "\"  value=\""
						+ d.getNodeValue() + "\"  checked=\"0\" />");
			}
		}
		sbf.append("</root>");
		// System.out.println(sbf.toString());
		out.print(sbf.toString());
		return null;
	}

	public ActionForward showCTPurpose(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		Integer logid = (Integer) request.getSession().getAttribute(
				"systemlogid");// 系统用户是否已经登录
		try{
		if (logid == null) {// 商家用户尚未登录
			// 返回-1
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><result>-1</result></root>");
			return null;
		}
		String purpose = "," + request.getParameter("purpose") + ",";
		List list = this.getShopService().getCTPurpose();
		for (int i = 0; i < list.size(); i++) {
			Dict d = (Dict) list.get(i);
			if (purpose.indexOf("," + d.getNodeCode() + ",") > -1) {
				sbf.append("<dict code=\"" + d.getNodeCode() + "\"  value=\""
						+ d.getNodeValue() + "\" checked=\"1\" />");
			} else {
				sbf.append("<dict code=\"" + d.getNodeCode() + "\"  value=\""
						+ d.getNodeValue() + "\" checked=\"0\"/>");
			}
		}
		sbf.append("</root>");
		// System.out.println(sbf.toString());
		out.print(sbf.toString());
		}catch(Exception e){
			e.printStackTrace();
		}
		return null;
	}

	public ActionForward showYlPurpose(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		Integer logid = (Integer) request.getSession().getAttribute(
				"systemlogid");// 系统用户是否已经登录

		if (logid == null) {// 商家用户尚未登录
			// 返回-1
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><result>-1</result></root>");
			return null;
		}
		String purpose = "," + request.getParameter("purpose") + ",";
		List list = this.getShopService().getYlPurpose();
		for (int i = 0; i < list.size(); i++) {
			Dict d = (Dict) list.get(i);
			if (purpose.indexOf("," + d.getNodeCode() + ",") > -1) {
				sbf.append("<dict code=\"" + d.getNodeCode() + "\"  value=\""
						+ d.getNodeValue() + "\" checked=\"1\" />");
			} else {
				sbf.append("<dict code=\"" + d.getNodeCode() + "\"  value=\""
						+ d.getNodeValue() + "\" checked=\"0\"/>");
			}
		}
		sbf.append("</root>");
		// System.out.println(sbf.toString());
		out.print(sbf.toString());
		return null;
	}

	public ActionForward showYdPurpose(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		Integer logid = (Integer) request.getSession().getAttribute(
				"systemlogid");// 系统用户是否已经登录

		if (logid == null) {// 商家用户尚未登录
			// 返回-1
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><result>-1</result></root>");
			return null;
		}
		String purpose = "," + request.getParameter("purpose") + ",";
		List list = this.getShopService().getYdPurpose();
		for (int i = 0; i < list.size(); i++) {
			Dict d = (Dict) list.get(i);
			if (purpose.indexOf("," + d.getNodeCode() + ",") > -1) {
				sbf.append("<dict code=\"" + d.getNodeCode() + "\"  value=\""
						+ d.getNodeValue() + "\" checked=\"1\" />");
			} else {
				sbf.append("<dict code=\"" + d.getNodeCode() + "\"  value=\""
						+ d.getNodeValue() + "\" checked=\"0\"/>");
			}
		}
		sbf.append("</root>");
		// System.out.println(sbf.toString());
		out.print(sbf.toString());
		return null;
	}

	public ActionForward showScPurpose(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		Integer logid = (Integer) request.getSession().getAttribute(
				"systemlogid");// 系统用户是否已经登录

		if (logid == null) {// 商家用户尚未登录
			// 返回-1
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><result>-1</result></root>");
			return null;
		}
		String purpose = "," + request.getParameter("purpose") + ",";
		List list = this.getShopService().getScPurpose();
		for (int i = 0; i < list.size(); i++) {
			Dict d = (Dict) list.get(i);
			if (purpose.indexOf("," + d.getNodeCode() + ",") > -1) {
				sbf.append("<dict code=\"" + d.getNodeCode() + "\"  value=\""
						+ d.getNodeValue() + "\" checked=\"1\" />");
			} else {
				sbf.append("<dict code=\"" + d.getNodeCode() + "\"  value=\""
						+ d.getNodeValue() + "\" checked=\"0\"/>");
			}
		}
		sbf.append("</root>");
		// System.out.println(sbf.toString());
		out.print(sbf.toString());
		return null;
	}

	/**
	 * 
	 * @param mapping
	 * @param pcUserForm
	 * @param request
	 * @param response
	 * @return
	 * @throws ServletException
	 * @throws IOException
	 */
	public ActionForward showCTShop(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		Integer logid = (Integer) request.getSession().getAttribute(
				"systemlogid");// 系统用户是否已经登录
		try{
		if (logid == null) {// 商家用户尚未登录
			// 返回-1
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><result>-1</result></root>");
			return null;
		}
		String id = request.getParameter("id");
		DdShop ds = this.getShopService().getDdShopDAO().findById(
				Integer.parseInt(id));
		if (ds == null) {// 对象不存在
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><result>-2</result></root>");
			return null;
		}
		int purposetype = 4;

		if (ds.getType().intValue() == 2) {
			purposetype = 6;
		} else if (ds.getType().intValue() == 3) {
			purposetype = 8;
		} else if (ds.getType().intValue() == 4) {
			purposetype = 10;
		} else if (ds.getType().intValue() == 5) {
			purposetype = 12;
		}
		DdSystemuser dsu = this.getDdSystemuserDAO().findByShopid(ds.getId());
		String logids = "";
		String logpas="";
		if(dsu!=null){
			logids = dsu.getLogid();
			logpas = dsu.getPassword();
		}
		int loge = 0;
		if(ds.getLoge0().intValue()==1&&ds.getLoge1().intValue()==1){
			loge=1;
		}else if(ds.getLoge0().intValue()==1&&ds.getLoge1().intValue()==0){
			loge=2;
		}else if(ds.getLoge0().intValue()==0&&ds.getLoge1().intValue()==1){
			loge=3;
		}
		sbf.append("<shop><syslogid>"
				+ logids
				+ "</syslogid><syslogpas>"
				+ logpas
				+ "</syslogpas><id>"
				+ ds.getId()
				+ "</id>"
				+ " <name>"
				+ ds.getName()
				+ "</name>"
				+ "<shophours>"
				+ ds.getShophours()
				+ "</shophours>"
				+ "<wifi>"
				+ ds.getWifi()
				+ "</wifi>"
				+ "<visa>"
				+ ds.getVisa()
				+ "</visa>"
				+ "<bankacc>"
				+ ds.getBankacc()
				+ "</bankacc>"
				+ "<bankacc2>"
				+ ds.getBankacc()
				+ "</bankacc2>"
				+ "<coupon3>"
				+ ds.getCoupon3()
				+ "</coupon3>"
				+ "<park>"
				+ ds.getPark()
				+ "</park>"
				+ "<bookreq>"
				+ ds.getBookreq()
				+ "</bookreq>"
				+ "<bankaccname>"
				+ ds.getBankaccname()
				+ "</bankaccname>"
				+ "<style>"
				+ this.getShopService().getStyleValue2(ds.getStyleType(),
						ds.getStyle(), this.getDictDAO())
				+ "</style>"
				+ "<styleType>"
				+ ds.getStyleType()
				+ "</styleType>"
				+ "<phone>"
				+ ds.getPhone()
				+ "</phone>"
				+ "<mobile>"
				+ ds.getMobile()
				+ "</mobile>"
				+ "<bossphone>"
				+ ds.getBossphone()
				+ "</bossphone>"
				+ "<pricedivide>"
				+ ds.getPricedivide()
				+ "</pricedivide>"
				+ " <address>"
				+ ds.getAddress()
				+ "</address>"
				+ "<cost>"
				+ ds.getCost()
				+ "</cost>"
				+ "<area>"
				+ ds.getArea()
				+ "</area>"
				+ "<road>"
				+ ds.getRoad()
				+ "</road>"
				+ "<landmark>"
				+ ds.getLandmark()
				+ "</landmark>"
				+ "<range>"
				+ ds.getRange()
				+ "</range>"
				+ "<bus>"
				+ ds.getBus()
				+ "</bus>"
				+ "<loge>"
				+ loge
				+ "</loge>"
				+ "<enddate>"
				+ DateStrFormat.getCurrentTime1(ds.getEnddate())
				+ "</enddate>"
				+ "<parking>"
				+ ds.getParking()
				+ "</parking>"
				+ "<posx>"
				+ ds.getPosx()
				+ "</posx>"
				+ "<posy>"
				+ ds.getPosy()
				+ "</posy>"
				+ "<posx_g>"
				+ ds.getPosx_g()
				+ "</posx_g>"
				+ "<posy_g>"
				+ ds.getPosy_g()
				+ "</posy_g>"
				+ "<purpose>"
				+ this.getShopService().getNodeValue(ds.getPurpose(),
						purposetype, this.getDictDAO(), true) + "</purpose>"
				+ "<service>" + ds.getService() + "</service>"
				+ "<description>" + ds.getDescription() + "</description>"
				+ "<belong>"+ ds.getBelong() + "</belong>" + "<hot>" + ds.getBelong()
				+ "</hot>" + "<bookprice>" + ds.getBookprice() + "</bookprice>"
				+ "<bookpriceused>" + ds.getBookpriceuse()
				+ "</bookpriceused><alive>" + ds.getAlive() + "</alive>"
				+ "<pic1>" + ds.getPic1() + "</pic1>" + "<pic2>" + ds.getPic2()
				+ "</pic2>" + "<pic3>" + ds.getPic3() + "</pic3>" + "<pic4>"
				+ ds.getPic4() + "</pic4>" + "<pic5>" + ds.getPic5()
				+ "</pic5>" + "<pic6>" + ds.getPic6() + "</pic6>" + "<pic7>"
				+ ds.getPic7() + "</pic7>" + "<pic8>" + ds.getPic8()
				+ "</pic8><pic9>" + ds.getPic9() + "</pic9><picht>"
				+ ds.getPicht() + "</picht>" + "<name1>" + ds.getName1()
				+ "</name1>" + "<url>" + ds.getUrl() + "</url>" + "<title>"
				+ ds.getTitle() + "</title>" + "<keyword>" + ds.getKeyword()
				+ "</keyword>" + "<des>" + ds.getDes() + "</des>"
				+"<discount>" + ds.getDiscount() + "</discount>");
		sbf.append("</shop></root>");
		out.print(sbf.toString());
		}catch(Exception e){
			e.printStackTrace();
		}
		return null;
	}

	public ActionForward queryShopGoods(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();

		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		Integer logid = (Integer) request.getSession().getAttribute(
				"systemlogid");// 系统用户是否已经登录

		if (logid == null) {// 商家用户尚未登录
			// 返回-1
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><result>-1</result></root>");
			return null;
		}
		String shopid = request.getParameter("shopid");
		String pageNo = request.getParameter("pageno");// 第几页
		String pageSize = request.getParameter("pagesize");// 每页记录数
		int i_pageNo = 1;
		if (pageNo != null && pageNo.trim().length() > 0) {
			i_pageNo = Integer.parseInt(pageNo);
		} else {
			i_pageNo = 1;
		}
		int i_pageSize = 10;
		if (pageSize != null && pageSize.trim().length() > 0) {
			i_pageSize = Integer.parseInt(pageSize);
		} else {
			i_pageSize = 10;
		}
		try {
			PageList list = this.getDdGoodDAO().findByShopid(
					Integer.parseInt(shopid), i_pageNo, i_pageSize);
			sbf.append("<shopgoodss total=\"" + list.getTotalCount() + "\">");
			for (int i = 0; i < list.size(); i++) {
				Object[] obj = (Object[]) list.get(i);
				DdShopgoods dsg = (DdShopgoods) obj[0];
				DdShop ddShop = (DdShop) obj[1];
				String str = dsg.getAlive() == 1 ? "是" : "否";
				sbf.append("<shopgoods goodsid=\"" + dsg.getId()
						+ "\" goodsname=\"" + dsg.getName() + "\"  price=\""
						+ dsg.getPrice() + "\" pic1=\"" + dsg.getPic1()
						+ "\" pic2=\"" + dsg.getPic2() + "\" pic3=\""
						+ dsg.getPic3() + "\" type=\"" + dsg.getType()
						+ "\" shopid=\"" + dsg.getShopid() + "\" alive=\""
						+ dsg.getAlive() + "\" alive_str=\"" + str
						+ "\"></shopgoods>");
			}
			sbf.append("</shopgoodss></root>");
			// System.out.println("ssssss:"+sbf.toString());
			out.print(sbf.toString());
			return null;
		} catch (Exception e) {
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>0</error></root>");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	public ActionForward shopGoodsinfo(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = response.getWriter();

		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		Integer logid = (Integer) request.getSession().getAttribute(
				"systemlogid");// 系统用户是否已经登录

		if (logid == null) {// 商家用户尚未登录
			// 返回-1
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><result>-1</result></root>");
			return null;
		}
		String id = request.getParameter("id");
		DdShopgoods dsg = this.getDdGoodDAO().findById(Integer.parseInt(id));

		try {

			sbf.append("<shopgoods> <goodsid>"
					+ dsg.getId()
					+ "</goodsid>"
					+ "<goodsname>"
					+ dsg.getName()
					+ "</goodsname>"
					+ "<price>"
					+ dsg.getPrice()
					+ "</price><price2>"
					+ dsg.getPrice2()
					+ "</price2>"
					+ "<price6>"
					+ dsg.getPrice6()
					+ "</price6>"
					+ "<price8>"
					+ dsg.getPrice8()
					+ "</price8>"
					+ "<price10>"
					+ dsg.getPrice10()
					+ "</price10>"
					+ "<price12>"
					+ dsg.getPrice12()
					+ "</price12>"
					+ "<type>"
					+ dsg.getType()
					+ "</type>"
					+ "<styletype>"
					+ dsg.getStyleType()
					+ "</styletype>"
					+ "<description>"
					+ dsg.getDescription()
					+ "</description>"
					+ "<cost>"
					+ dsg.getCost()
					+ "</cost>"
					+ "<discount>"
					+ dsg.getDiscount()
					+ "</discount>"
					+ "<discount6>"
					+ dsg.getDiscount6()
					+ "</discount6>"
					+ "<discount8>"
					+ dsg.getDiscount8()
					+ "</discount8>"
					+ "<discount10>"
					+ dsg.getDiscount10()
					+ "</discount10>"
					+ "<discount12>"
					+ dsg.getDiscount12()
					+ "</discount12>"
					+ "<purpose>"
					+ this.getShopService().getNodeValue(dsg.getPurpose(), 10,
							this.getDictDAO(), true)
					+ "</purpose>"
					+ "<sendto>"
					+ this.getShopService().getNodeValue(dsg.getSendto(), 15,
							this.getDictDAO(), true)
					+ "</sendto>"
					+ "<style>"
					+ this.getShopService().getStyleValue3(dsg.getStyleType(),
							dsg.getStyle(), this.getDictDAO()) + "</style>"
					+ "<url>" + dsg.getUrl() + "</url>" + "<title>"
					+ dsg.getTitle() + "</title>" + "<keyword>"
					+ dsg.getKeyword() + "</keyword>" + "<des>" + dsg.getDes()
					+ "</des><pic1>" + dsg.getPic1() + "</pic1><pic2>"
					+ dsg.getPic2() + "</pic2><pic3>" + dsg.getPic3()
					+ "</pic3><pic4>" + dsg.getPic4() + "</pic4><pic5>"
					+ dsg.getPic5() + "</pic5><pic6>" + dsg.getPic6()
					+ "</pic6><pic7>" + dsg.getPic7() + "</pic7><pic8>"
					+ dsg.getPic8() + "</pic8></shopgoods>");
			sbf.append("</root>");
			// System.out.println(sbf.toString());
			out.print(sbf.toString());
			return null;
		} catch (Exception e) {
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><error>0</error></root>");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}

	/**
	 * Method execute 上传照片
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward upload(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		try {
			MainForm mainForm = (MainForm) form;
			FormFile file = mainForm.getFile();// 图片对象
			// String rootpath = request.getRealPath("");// 根路径流
			String typeid = request.getParameter("typeid");// 商家ID/商品ID
			String types = request.getParameter("types");// 类型 1为商家、2为商品
			String imageid = request.getParameter("imageid");// 第几张图片
			// HcPtdcacvUser user = (HcPtdcacvUser)
			// request.getSession().getAttribute(
			// "user");
			String temp = "";
			if (types != null && types.trim().length() > 0 && types.equals("1")) {
				temp = "\\shop_img\\";// 添加文字的图片路径
			} else if (types != null && types.trim().length() > 0
					&& types.equals("2")) {
				temp = "\\pro_img\\";// 添加文字的图片路径
			}
			String userpath = request.getRealPath("") + temp;// 绝对路径
			@SuppressWarnings("unused")
			File file1 = new File(userpath);// 根路径
			if (!file1.exists()) {
				new File(userpath).mkdir(); // 创建路径
			}
			userpath += "" + typeid + "\\";// 商家路径
			File file2 = new File(userpath);
			if (!file2.exists()) {
				new File(userpath).mkdir(); // 创建路径
			}
			if (file != null && file.getFileSize() > 0) {// 上传
				new File(userpath + "\\pic" + imageid + ".jpg").delete();
				String filepath = new UpFile().uploadfile(userpath + "\\pic"
						+ imageid + ".jpg", file, imageid);
				if (filepath != null && filepath.trim().length() > 0) {
					DdShopgoodsDAO dsdd = this.getDdGoodDAO();
					ShopService ss = this.getShopService();// 获取商家Servcie
					DdShopDAO dsd = ss.getDdShopDAO();

					try {
						if (imageid != null && imageid.trim().length() > 0) {
							if (types != null && types.trim().length() > 0
									&& types.equals("1")) {// 商家
								DdShop ds = ss.getDdShopDAO().findById(
										Integer.parseInt(typeid));
								if (imageid.equals("1")) {// 判断是那张图片
									ds.setPic1("1");
								}
								if (imageid.equals("2")) {
									ds.setPic2("1");
								}
								if (imageid.equals("3")) {
									ds.setPic3("1");
								}
								if (imageid.equals("4")) {
									ds.setPic4("1");
								}
								if (imageid.equals("5")) {
									ds.setPic5("1");
								}
								if (imageid.equals("6")) {
									ds.setPic6("1");
								}
								if (imageid.equals("7")) {
									ds.setPic7("1");
								}
								if (imageid.equals("8")) {
									ds.setPic8("1");
								}
								if (imageid.equals("9")) {
									ds.setPic9("1");
								}
								if (imageid.equals("ht")) {
									ds.setPicht("1");
								}
								this.getDdShopDAO().saveOrUpdate(ds);
							} else if (types != null
									&& types.trim().length() > 0
									&& types.equals("2")) {
								DdShopgoods ds = dsdd.findById(Integer
										.parseInt(typeid));
								if (imageid.equals("1")) {// 判断是那张图片
									ds.setPic1("1");
								}
								if (imageid.equals("2")) {
									ds.setPic2("1");
								}
								if (imageid.equals("3")) {
									ds.setPic3("1");
								}
								if (imageid.equals("4")) {
									ds.setPic4("1");
								}
								if (imageid.equals("5")) {
									ds.setPic5("1");
								}
								if (imageid.equals("6")) {
									ds.setPic6("1");
								}
								if (imageid.equals("7")) {
									ds.setPic7("1");
								}
								if (imageid.equals("8")) {
									ds.setPic8("1");
								}
								dsdd.saveOrUpdate(ds);
							}
						}
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					request.setAttribute("msg", "上传成功");
				}
			}

			request.setAttribute("typeid", typeid);
			request.setAttribute("types", types);
			request.setAttribute("imageid", imageid);
			return mapping.findForward("upload");
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	public ActionForward newshopgoods(ActionMapping mapping,
			ActionForm pcUserForm, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control", "no-cache");

		PrintWriter out = response.getWriter();
		Integer logid = (Integer) request.getSession().getAttribute(
				"systemlogid");// 系统用户是否已经登录

		if (logid == null) {// 商家用户尚未登录
			// 返回-1
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><result>-1</result></root>");
			return null;
		}
		StringBuffer sbf = new StringBuffer(
				"<?xml version=\"1.0\" encoding=\"utf-8\"?><root>");
		try {
			DdShopgoods dsgg = new DdShopgoods();
			String id = request.getParameter("id");
			if (id != null & id.trim().length() > 0) {
				dsgg = this.getDdGoodDAO().findById(Integer.parseInt(id));
			}
			String shopid = request.getParameter("shopid");
			if (shopid != null && shopid.trim().length() > 0) {
				dsgg.setShopid(Integer.parseInt(shopid));
			}
			String name = request.getParameter("name");
			if (name != null && name.trim().length() > 0) {
				dsgg.setName(name);
			}
			String price = request.getParameter("price");
			String price2 = request.getParameter("price2");
			if (price != null && price.trim().length() > 0) {
				dsgg.setPrice(Float.parseFloat(price));
			}
			if (price2 != null && price2.trim().length() > 0) {
				dsgg.setPrice2(Float.parseFloat(price2));
			}
			String price6 = request.getParameter("price6");
			if (price6 != null && price6.trim().length() > 0) {
				dsgg.setPrice6(Float.parseFloat(price6));
			}
			String price8 = request.getParameter("price8");
			if (price8 != null && price8.trim().length() > 0) {
				dsgg.setPrice8(Float.parseFloat(price8));
			}
			String price10 = request.getParameter("price10");
			if (price10 != null && price10.trim().length() > 0) {
				dsgg.setPrice10(Float.parseFloat(price10));
			}
			String price12 = request.getParameter("price12");
			if (price12 != null && price12.trim().length() > 0) {
				dsgg.setPrice12(Float.parseFloat(price12));
			}
			String sendto = request.getParameter("sendto");
			if (sendto != null && sendto.trim().length() > 0) {
				dsgg.setSendto(Integer.parseInt(sendto));
			}
			String sendto_str = request.getParameter("sendto_str");
			if (sendto_str != null && sendto_str.trim().length() > 0) {
				String str = "";
				String _sendto_str[] = sendto_str.split(",");
				for (int i = 0; i < _sendto_str.length; i++) {
					str = str
							+ this.getDictDAO().findByTypeAndCode(15,
									Integer.parseInt(_sendto_str[i]))
									.getNodeValue() + ",";
				}
				if (str != null && str.length() > 0) {
					str = str.substring(0, str.length() - 1);
				}
				dsgg.setSendtovalue(str);
			}
			String description = request.getParameter("description");
			if (description != null && description.trim().length() > 0) {
				dsgg.setDescription(description);
			}
			String cost = request.getParameter("cost");
			if (cost != null && cost.trim().length() > 0) {
				dsgg.setCost(Integer.parseInt(cost));
			}
			String discount = request.getParameter("discount");
			if (discount != null && discount.trim().length() > 0) {
				dsgg.setDiscount(Float.parseFloat(discount));
			}
			String discount6 = request.getParameter("discount6");
			if (discount6 != null && discount6.trim().length() > 0) {
				dsgg.setDiscount6(Float.parseFloat(discount6));
			}
			String discount8 = request.getParameter("discount8");
			if (discount8 != null && discount8.trim().length() > 0) {
				dsgg.setDiscount8(Float.parseFloat(discount8));
			}
			String discount10 = request.getParameter("discount10");
			if (discount10 != null && discount10.trim().length() > 0) {
				dsgg.setDiscount10(Float.parseFloat(discount10));
			}
			String discount12 = request.getParameter("discount12");
			if (discount12 != null && discount12.trim().length() > 0) {
				dsgg.setDiscount12(Float.parseFloat(discount12));
			}
			String styletype = request.getParameter("styletype");
			String stylestr = "";
			if (styletype != null && styletype.length() > 0) {
				dsgg.setStyleType(Integer.parseInt(styletype));
				Dict d = (Dict) this.getDictDAO().findByNodeCode(
						dsgg.getStyleType()).get(0);
				stylestr = d.getNodeValue() + ",";
			}
			String style = request.getParameter("style");
			if (style != null && style.trim().length() > 0) {
				dsgg.setStyle(Long.parseLong(style));
			}
			String style_str = request.getParameter("style_str");
			if (style_str != null && style_str.trim().length() > 0) {
				String str[] = style_str.split(",");
				for (int i = 0; i < str.length; i++) {
					if (str[i] != null && str[i].length() > 0) {
						Dict d = (Dict) this.getDictDAO().findByTypeAndCode(14,
								dsgg.getStyleType(), Integer.parseInt(str[i]));
						stylestr = stylestr + d.getNodeValue() + ",";
					}
				}
				if (stylestr.length() > 0) {
					stylestr = stylestr.substring(0, stylestr.length() - 1);
				}
				dsgg.setStylevalue(stylestr);
			}
			String purpose = request.getParameter("purpose");
			if (purpose != null && purpose.trim().length() > 0) {
				dsgg.setPurpose(Integer.parseInt(purpose));
			}
			String purpose_str = request.getParameter("purpose_str");
			if (purpose_str != null && purpose_str.trim().length() > 0) {
				String str1[] = purpose_str.split(",");
				String purposestr = "";
				for (int i = 0; i < str1.length; i++) {
					if (str1[i] != null && str1[i].length() > 0) {
						Dict d = (Dict) this.getDictDAO().findByTypeAndCode(10,
								Integer.parseInt(str1[i]));
						purposestr = purposestr + d.getNodeValue() + ",";
					}
				}
				if (purposestr.length() > 0) {
					purposestr = purposestr.substring(0,
							purposestr.length() - 1);
				}
				dsgg.setPurposevalue(purposestr);
			}
			if (request.getParameter("url") != null) {
				dsgg.setUrl(request.getParameter("url"));
			}
			if (request.getParameter("title") != null) {
				dsgg.setTitle(request.getParameter("title"));
			}
			if (request.getParameter("keyword") != null) {
				dsgg.setKeyword(request.getParameter("keyword"));
			}
			if (request.getParameter("des") != null) {
				dsgg.setDes(request.getParameter("des"));
			}
			if (id != null & id.trim().length() > 0) {
				this.getDdGoodDAO().saveOrUpdate(dsgg);
				// out.print(sbf.toString());
				sbf.append("<result>1</result></root>");
				out.print(sbf.toString());
				// System.out.println(sbf.toString());
			} else {
				List list = this.getDdGoodDAO().findByShopAndName(
						Integer.parseInt(shopid), name);
				if (list.size() != 0) {
					sbf.append("<result>2</result></root>");
					out.print(sbf.toString());
					return null;
				} else {
					dsgg.setShopname(this.getDdShopDAO().findById(
							dsgg.getShopid()).getName());
					dsgg.setType(this.getDdShopDAO().findById(dsgg.getShopid())
							.getType()
							+ "");
					this.getDdGoodDAO().saveOrUpdate(dsgg);
					sbf.append("<result>1</result></root>");
					out.print(sbf.toString());
					// System.out.println(sbf.toString());
				}
			}
			return null;
		} catch (Exception e) {
			out
					.print("<?xml version=\"1.0\" encoding=\"utf-8\"?><root><result>0</result></root>");
			out.flush();
			out.close();
			e.printStackTrace();
			return null;
		}
	}
}
